﻿using System;
using System.Web;
using YTBZ.PUB.COMMON;

namespace YTBZ
{
    public partial class LOGIN : System.Web.UI.Page
    {
        #region pageLoad
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                Session.Clear();
                //if (hidCURRTEST.Value == "1") { lbtnLogin_Click(null, null); }
                if (Request.Cookies["YHName"] != null)
                {
                    //toyx 201607010
                    System.Text.Encoding enc = System.Text.Encoding.GetEncoding("gb2312");
                    txtUserName.Text = HttpUtility.UrlDecode(Request.Cookies["YHName"].Value, enc);
                }
                txtUserName.Focus();
                //TEST
            }
        }
        #endregion

        #region pageLogin
        protected void lbtnLogin_Click(object sender, EventArgs e)
        {
            YTBZ.BasePage TT = new BasePage();
            string strUser = txtUserName.Text,
                strPass = txtPassword.Text;
            string str_MM = PasswordKey.encryptPwd(txtPassword.Text.Trim());
            //if (hidCURRTEST.Value == "1") { strUser = "admin"; strPass = "111111"; }
            string strBack = TT.getUserLogin(strUser, strPass);
            if (strBack != "")
            {
                if (strBack.Substring(0, 4) == "OVER")
                {

                    string strjs = "<Script Language=\"javascript\">\n";
                    strjs += "alert(\""+ strBack.Replace("OVER", "") + "\")\n";
                    strjs += "location.href=\"/PUB/CHANGEPASS.aspx?flag=login\"\n";
                    strjs += "</Script>";
                    Response.Write(strjs);
                }
                else
                {
                    txtUserName.Focus();
                    lblERR.Text = strBack;
                    TT.jsMessage(strBack);
                    System.Text.Encoding enc = System.Text.Encoding.GetEncoding("gb2312");
                    Context.Response.Cookies["YHName"].Value = HttpUtility.UrlEncode(strUser, enc);
                    TT.proREG("用户登录", "登录失败", "用户：" + txtUserName.Text + " 登录失败：" + strBack, txtUserName.Text, null, null, null, null);
                }
            }
            else
            {
                TT.proREG("用户登录", "登录成功", "用户：" + txtUserName.Text + " 登录成功" , null, null, null, null, null);
                Response.Redirect("INDEX.ASPX");
            }
        }

        #endregion
        
    }
}